<?php

class step3UpdateAction extends sfAction
{
    public function execute($request)
    {
		$page_id = $request->getParameter("page_id");
		// explode each website from textarea
        $page_websites = $request->getParameter("page_websites");
		$page_websites .= ";";
		$page_websites = preg_replace("/\s+/", ";", $page_websites);
		$page_websites = preg_replace("/;+/", ";", $page_websites);
		
		$arr_website = explode(";", $page_websites);
		// get user id

		// insert url to database
		foreach ($arr_website as $website)
		{
			$website = trim($website);
			if ($website != "")
			{
				$pageWebsiteExist = Doctrine_Core::getTable("PageWebsite")->findOneByPageIdAndUrl($page_id, $website);
				if (!$pageWebsiteExist)
				{
					$page_website = new PageWebsite();
					$page_website->page_id = $page_id;
					$page_website->url = $website;
					$page_website->save();
				}
			}
		}
		
		return $this->renderText('Success.');
        //return sfView::NONE;
    }
}